<script setup>
import { ref, onMounted } from 'vue'
import HomePanel from './HomePanel.vue'
import GoodsItem from './GoodsItem.vue'
import { findGoodsAPI } from '@/apis/home.js'
// 定义数据
const goodsProduct = ref([])
// 定义请求数据
const getGoods = async () => {
  const res = await findGoodsAPI()
  goodsProduct.value = res.result
  //console.log('所有商品模块',res)
}
onMounted(() => getGoods())
</script>

<template>
  <HomePanel :title="cate.name" :sub-title="cate.saleInfo" v-for="cate in goodsProduct" :key="cate.id">
    <!--默认插槽 内容-->
    <div class="goods-group">
      <RouterLink class="cover" to="/">
        <img :src="cate.picture" />
        <strong class="label">
          <span>{{cate.name}}馆</span>
          <span>{{cate.saleInfo}}</span>
        </strong>
      </RouterLink>
      <div class="goods-list">
        <ul>
          <li v-for="goods in cate.goods" :key="goods.id">
            <!--<RouterLink class="goods-item" to="/">
              <div class="pic"><img :src="goods.picture" /></div>
              <div class="info-desc">
                <p class="name ellipsis-2">{{goods.name}}</p>
                <p class="desc ellipsis">{{goods.desc}}</p>
                <p class="price">{{goods.price}}</p>
              </div>
              <div class="extra">
                <span>找相似</span>
                <span>发现现多宝贝 ></span>
              </div>
            </RouterLink>-->
            <GoodsItem :goods="goods"></GoodsItem>
          </li>
        </ul>
      </div>
    </div>
  </HomePanel>
</template>

<style lang="scss" scoped>
.goods-group{
  display: flex;
  .cover{
    width: 250px;
    height: 734px;
    margin-right: 20px;
    position: relative;
    img{
      width: 100%;
      height: 100%;
      -o-object-fit: cover;
      object-fit: cover;
    }
    .label{
      width: 188px;
      height: 66px;
      display: flex;
      font-size: 18px;
      color: #fff;
      line-height: 66px;
      font-weight: 400;
      position: absolute;
      left: 0;
      top: 50%;
      transform: translate3d(0,-50%,0);
      span{
        text-align: center;
        flex: 1;
        background: rgba(0,0,0,.7);
      }
      span:first-child{
        width: 76px;
        background: rgba(0,0,0,.9);
      }
    }
  }
  .goods-list{
    width: 970px;
    ul{
      display: flex;
      flex-wrap: wrap;
      margin-left: -10px;
      margin-right: -10px;
      margin-top: -20px;
    }
    li{
      width: 25%;
      padding: 0 10px;
      margin-top: 20px;
    }
    .goods-item{
      display: block;
      position: relative;
      overflow: hidden;
      border: 1px solid #ededed;
      transition: all .5s;
      .pic{
        width: 100%;
        height: 225px;
        img{
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      .info-desc{
        padding: 15px;
      }
      p{
        font-size: 14px;
      }
      p.name{
        height: 40px;
      }
      p.desc{
        font-size: 12px;
        color: #999;
        height: 17px;
        margin-top: 5px;
      }
      p.price{
        margin-top: 10px;
        font-size: 20px;
        color: $priceColor;
      }
      .extra{
        position: absolute;
        left: 0;
        bottom: 0;
        height: 86px;
        width: 100%;
        background: #27ba9b;
        text-align: center;
        transform: translate3d(0,100%,0);
        transition: all .5s;
        span{
          display: block;
          color: #fff;
          width: 120px;
          margin: 0 auto;
          line-height: 30px;
        }
        span:first-child{
          font-size: 18px;
          border-bottom: 1px solid #fff;
          line-height: 40px;
          margin-top: 5px;
        }
      }
      &:hover{
        border-color: $xtxColor;
      }
      &:hover .extra{
        transform: none;
      }
    }
  }
}
</style>